package com.ruoyi.quartz.task;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.ruoyi.system.service.aggregation.IProductStockService;

/**
 * 库存同步定时任务
 * 定期将Redis库存同步到MySQL
 * 
 * @author ruoyi
 * @date 2025-01-13
 */
@Component("stockSyncTask")
public class StockSyncTask
{
    @Autowired
    private IProductStockService productStockService;

    /**
     * 同步库存到数据库
     * 建议：每5分钟执行一次
     */
    public void syncStock()
    {
        System.out.println("🔄 开始执行库存同步任务...");
        
        try
        {
            productStockService.syncAllStockToDb();
            System.out.println("✅ 库存同步任务完成");
        }
        catch (Exception e)
        {
            System.err.println("❌ 库存同步任务执行失败：" + e.getMessage());
            e.printStackTrace();
        }
    }
}

